﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using WebDownload.Properties;

namespace WebDownload
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string path = Application.StartupPath + "\\";
            string dllFileName = "HtmlAgilityPack.dll";
            //******加载HtmlAgilityPack.dll******
            if (!File.Exists(path + dllFileName)) //文件不存在
            {
                //方法一：增加到资源文件，然后解压
                FileStream fs = new FileStream(path + dllFileName, FileMode.CreateNew, FileAccess.Write);
                byte[] buffer = Resources.HtmlAgilityPack;//Resource是资源文件的名称
                fs.Write(buffer, 0, buffer.Length);
                fs.Close();

                //方法二：嵌入的资源，读取再释放
                //BufferedStream inStream = null;
                //FileStream outStream = null;
                //try
                //{
                //    Assembly asm = Assembly.GetExecutingAssembly(); //读取嵌入式资源
                //    inStream = new BufferedStream(asm.GetManifestResourceStream("ResourceManage.Unionnet.Core.dll"));
                //    outStream = new FileStream(path + dllFileName, FileMode.Create, FileAccess.Write);
                //    byte[] buffer = new byte[inStream.Length];
                //    int length;
                //    while ((length = inStream.Read(buffer, 0, buffer.Length)) > 0)
                //    {
                //        outStream.Write(buffer, 0, length);
                //    }
                //    outStream.Flush();
                //}
                //finally
                //{
                //    if (outStream != null)
                //    {
                //        outStream.Close();
                //    }
                //    if (inStream != null)
                //    {
                //        inStream.Close();
                //    }
                //}



            }
            Application.Run(new Form1());
        }
    }
}
